package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.ApprovalFileDao;
import cn.topevery.garden.entity.po.ApprovalFile;
import cn.topevery.garden.entity.query.ApprovalFileQuery;
import cn.topevery.garden.entity.vo.ApprovalFileVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.CommandType;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 批后数据 附件表
 *
 * @author code-generate
 * @date 2022-02-16
 */
@Repository
public class ApprovalFileDaoImpl extends BaseDaoImpl<ApprovalFile> implements ApprovalFileDao {
    @Override
    public <P extends DbCsp> List<ApprovalFile> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<ApprovalFileVO> listPage(ApprovalFileQuery query) {
        String table = "t_approval_file taf";

        String columns = "taf.*";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("taf.c_id desc");
        sqlQueryMate
                .where(true, "taf.c_db_status", ScriptConditionEnum.Eq, 0)
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, ApprovalFileVO.class);
    }

    @Override
    public ApprovalFile getEntityByColumn(String key,String value){
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }

    @Override
    public List<ApprovalFile> getListByPid(Integer pid) {
        String table = "t_approval_file taf";

        String columns = "taf.*";

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns);
        sqlQueryMate
                .where(true, "taf.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(true, "taf.c_main_id", ScriptConditionEnum.Eq, pid)
        ;
        return selectList(sqlQueryMate, ApprovalFile.class);
    }

    @Override
    public void deleteById(Integer pId) {
        String sql = "delete from t_approval_file where c_main_id = " + pId;
        run(sql, CommandType.Text, dbCommand -> {
            dbCommand.executeNonQuery();
        });
    }
}
